<?php
/**
 * Created by JetBrains PhpStorm.
 * User: wulashan
 * Date: 17.04.13
 * Time: 23:12
 * To change this template use File | Settings | File Templates.
 */

class Helper {


    public static function  isJessi(){
        //$isJessi = false;
        $isJessi = false;

        if (Session::get('loggedIn') && strtolower(Session::get('userName')) == 'jessica'){
            $isJessi = true;
            if(Session::get('jessiIsHere') !== true){
                mail('boyz_menz@hotmail.com', 'Jessi is here now', 'She may be missing U :)');
            }

            Session::set('jessiIsHere', true);

        }
        return $isJessi;
    }

     public static function  getJessiVideoSize(){
        $aSize = array('h'=>1, 'w'=>'1');
         if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'ipad') || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'iphone'))){
             $aSize = array('h'=>315, 'w'=>420);
         }

         return $aSize;
     }

    public static function renderTableTitle($width, $label){
       return  '<td width="'.$width.'%" valign="top">
                    <div><strong>'.$label.'</strong></div>
                </td>';
    }

    public static function renderTdItem($width, $data, $link = false){
        $linkStart = '';
        $linkEnd = '';

        if ($link !== false){
            $linkStart = $linkStart = '<a href="'.$link.'" >';
            $linkEnd = '</a>';
        }
        echo '<td width="'.$width.'%" valign="top"><div class="column">'.$linkStart.$data.$linkEnd.'</div></td>';
    }


    public static function renderTableItem($label, $data){

        $content = '<tr>
            <td class="contact" width="35%">'.$label.'</td>
            <td class="contact" width="65%">'.$data.'</td>
        </tr>';
        return $content;

    }


    /**
     * @param $tplFile
     * @param $content
     * @param $prefix
     */
    public static  function download_send_headers($tplFile, $content, $prefix = 'ams') {
        $filename = $prefix."_".date("Y-m-d-His",time()).".csv";

        $fh = fopen($tplFile,"w");
        //fwrite($fh,utf8_decode( $content ) );
        fwrite($fh, $content ) ;
        fclose($fh);
        $fp = fopen($tplFile,"r");
        if(!$fp){
            echo "ERROR: Konnte Datei nicht erstellen! <br/>";
        } else{
            echo fread($fp, 250*1000);
            $application="text/csv";
            header( "Content-Type: $application" );
            header( "Content-Disposition: attachment; filename=$filename");
            header( "Content-Description: csv File" );
            header( "Pragma: no-cache" );
            header( "Expires: 0" );
        }
    }

    public static function roundUp ($value, $places=0) {
        if ($places < 0) { $places = 0; }
        $mult = pow(10, $places);
        return ceil($value * $mult) / $mult;
    }



}

?>
